package org.gap.wizards.world;

import java.io.IOException;

import org.gap.jseed.injection.annotation.Singleton;
import org.gap.wizards.utils.PersistenceUtils;

@Singleton
public class WorldTimer implements TimerState {
	private int ticks = 0;
	
	@Override
	public void tick() {
		ticks++;
	}

	@Override
	public int getTime() {
		return ticks;
	}
	
	@Override
	public void persist() {
		try {
			PersistenceUtils.setField("Timer", ticks);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void load() {
		try {
			ticks = PersistenceUtils.getIntField("Timer");
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("Failed to load data", e);
		}
	}
}
